package cn.edu.hzvtc.controller;

import cn.edu.hzvtc.entity.Department;
import cn.edu.hzvtc.entity.ReturnMsg;
import cn.edu.hzvtc.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/getCount")
    @ResponseBody
    public ReturnMsg getCounts(){
        List<Department> departments = departmentService.selectGroupByDept();
        PageInfo pageInfo = new PageInfo(departments);
        return ReturnMsg.success().add("pageInfo",pageInfo);
    }

    @RequestMapping("/chart")
    public String chart(){
        return "chart";
    }

    @RequestMapping("/depts")
    @ResponseBody
    public ReturnMsg getDepts(){
        List<Department> depts = departmentService.getAll();

        return ReturnMsg.success().add("depts",depts);
    }

}
